package com.zenithmind.news.pojo.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.zenithmind.common.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 新闻统计实体类 - 遵循单一职责原则
 * 专门负责新闻的统计数据
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("news_statistics")
@Schema(description = "新闻统计实体")
public class NewsStatistics extends BaseEntity {

    /**
     * 新闻ID
     */
    @Schema(description = "新闻ID")
    private String newsId;

    /**
     * 阅读量
     */
    @Schema(description = "阅读量")
    private Long viewCount = 0L;

    /**
     * 点赞数
     */
    @Schema(description = "点赞数")
    private Long likeCount = 0L;

    /**
     * 收藏数
     */
    @Schema(description = "收藏数")
    private Long favoriteCount = 0L;

    /**
     * 分享数
     */
    @Schema(description = "分享数")
    private Long shareCount = 0L;

    /**
     * 评论数
     */
    @Schema(description = "评论数")
    private Long commentCount = 0L;

    /**
     * 内容质量评分（0-1）
     */
    @Schema(description = "内容质量评分（0-1）")
    private Double qualityScore = 0.8;

    /**
     * 热度评分
     */
    @Schema(description = "热度评分")
    private Double hotScore = 0.0;

    /**
     * 增加阅读量
     */
    public void incrementViewCount() {
        this.viewCount = (this.viewCount == null ? 0L : this.viewCount) + 1;
    }

    /**
     * 增加点赞数
     */
    public void incrementLikeCount() {
        this.likeCount = (this.likeCount == null ? 0L : this.likeCount) + 1;
    }

    /**
     * 减少点赞数
     */
    public void decrementLikeCount() {
        this.likeCount = Math.max(0L, (this.likeCount == null ? 0L : this.likeCount) - 1);
    }

    /**
     * 增加收藏数
     */
    public void incrementFavoriteCount() {
        this.favoriteCount = (this.favoriteCount == null ? 0L : this.favoriteCount) + 1;
    }

    /**
     * 减少收藏数
     */
    public void decrementFavoriteCount() {
        this.favoriteCount = Math.max(0L, (this.favoriteCount == null ? 0L : this.favoriteCount) - 1);
    }

    /**
     * 增加分享数
     */
    public void incrementShareCount() {
        this.shareCount = (this.shareCount == null ? 0L : this.shareCount) + 1;
    }

    /**
     * 增加评论数
     */
    public void incrementCommentCount() {
        this.commentCount = (this.commentCount == null ? 0L : this.commentCount) + 1;
    }

    /**
     * 减少评论数
     */
    public void decrementCommentCount() {
        this.commentCount = Math.max(0L, (this.commentCount == null ? 0L : this.commentCount) - 1);
    }
}
